package com.city.helper;

import com.city.domain.pub.*;
import com.city.service.city.CityTownService;
import com.city.service.city.CityVillageService;
import com.city.service.pub.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.List;

/**
 * @Author: 李顺时
 * @Description: pubuser表中的数据判断 将数字转换为字符
 * @Date: Create in 20:33 2018/9/20
 * @Modified By:
 * */

@Component
public class PubUserJudgeUtils {

    @Autowired
    public SaveService saveService;

    @Autowired
    private PubNationCategoryService pubNationCategoryService;

    @Autowired
    private PubFamilyRelationshipService relationshipService;

    @Autowired
    private PubIndustryCategoryService industryCategoryService;

    @Autowired
    private  PubPoliticalOutlookService outlookService;


    private static PubUserJudgeUtils pubUserJudgeUtils;
    @PostConstruct
    public void init(){
        pubUserJudgeUtils = this;
        pubUserJudgeUtils.pubNationCategoryService = this.pubNationCategoryService;
        pubUserJudgeUtils.relationshipService = this.relationshipService;
        pubUserJudgeUtils.industryCategoryService = this.industryCategoryService;
        pubUserJudgeUtils.outlookService = this.outlookService;

    }
    /**
     * @Author: 李顺时
     * @Description: 返回民族的名称
     * @param nationId 民族表中的id
     * @Date: 21:20 2018/8/13
     */
    public String getNationName(int nationId){
        String nationName = pubUserJudgeUtils.pubNationCategoryService.findOne(nationId).getName();
        if( nationName== null)
        {
            return "数据错误";
        }
        return nationName;
    }

    /**
     * @Author: 李顺时
     * @Description: 获取和户主的家庭关系
     * @param type 关系表中的id
     * @Date: 21:27 2018/8/13
     */
    public String getRelation(int type){
        List<PubFamilyRelationship> familyRelationships = pubUserJudgeUtils.relationshipService.findALL();
        for (PubFamilyRelationship r: familyRelationships) {
            if(type == r.getId()){
                return r.getName();
            }
        }
        return "数据错误";

    }

    public String getWorkStatus(String type){
        if(("2").equalsIgnoreCase(type)){
            return "创业";
        }else if("1".equalsIgnoreCase(type)){
            return  "已就业";
        }else {
            return  "无业";
        }
    }


    public String getSex(Integer type){
        if(type == 1){
            return  "女";
        }else{
            return "男";
        }
    }
    /**
     * 需要完善分类、多添加一个类作为传递数据用等。
     */


    public String getIndustryName(int type){
        List<PubIndustryCategory> pubIndustryCategories = pubUserJudgeUtils.industryCategoryService.findAll();
        for (PubIndustryCategory i: pubIndustryCategories) {
            if(type == i.getId()){
                return i.getName();
            }
        }
        return "数据错误";
    }


    public String getPoliticalOutlook(String id){
        List<PubPoliticalOutlook> pubPoliticalOutlooks = pubUserJudgeUtils.outlookService.findAll();
        for (PubPoliticalOutlook i: pubPoliticalOutlooks) {
            if(Integer.parseInt(id) == i.getId()){
                return i.getName();
            }
        }
        return "数据错误";
    }


    public String checkIsDb(int db){
        if(db == 0){
            return "正常";
        }
        else{
            return "低保户";
        }
    }

    public String checkIsWb(int wb){
        if(wb == 0){
            return "正常";
        }
        else{
            return "五保户";
        }
    }

    public String checkIsLdl(int ldl){
        if(ldl == 0){
            return "正常";
        }
        else{
            return "无劳动力";
        }
    }


    public String checkIsCj(int cj){
        if(cj == 0){
            return "正常";
        }
        else{
            return "残疾";
        }
    }

    public String checkIsBx(int bx){
        if(bx == 0){
            return "正常";
        }
        else{
            return "未购买保险";
        }
    }

    public String checkHealthStatus(int h){
        if(h == 0){
            return "正常";
        }
        else{
            return "不健康";
        }
    }


    public String beizhu(PubUser pubUser){
        String s ="身体状况:";
        if(pubUser.getHealthStatus() == 3){
            s+= "患大病";
        }else if(pubUser.getHealthStatus() == 2){
            s+= "长期慢性病";
        }else{
            s+= "健康";
        }
        if(pubUser.getIsBx() ==0)
        {
            s +="、未";
        }
        if(pubUser.getIsBx() ==1){
            s +="、已";
        }
        s +="购买保险";
        if(pubUser.getIsCj()==1){
            s += "、残疾";
        }
        if(pubUser.getIsDb() ==1){
            s+="、是低保户";
        }
        if(pubUser.getIsWb() ==1){
            s +="、是五保户";
        }
        if(pubUser.getIsLdl() ==0){
            s +="、无劳动力";
        }
        s+="。";
        return s;
    }


}
